<style>
.uploadify-queue-item{
	width: 340px;
}
</style>
<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'north',border:false" style=" height:45px;padding:5px;border-bottom:1px solid #95B8E7;">
        <div style="float:left; padding:4px 0 0;">
            <a href="#" class="easyui-linkbutton emailaddsub" data-options="iconCls:'icon-ok'" onclick="addemail()">发送</a>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="javascript:emailclose();">取消</a>
        </div>
        <div style="float:right; padding:3px;">
        	<a id="emailcc" href="#" class="easyui-linkbutton" data-options="plain:true" onclick="javascript:emailcc()">抄送</a>
        </div>
    </div>
    <div data-options="region:'center',border:false" style=" padding-bottom:10px;;-moz-user-select:text; -webkit-user-select:text; -ms-user-select:text; -khtml-user-select:text; user-select:text;">
    	<div style="padding:6px;">          	         
            <div style="padding-left: 64px;margin:5px;font-size: 12px; font-family:'Microsoft Yahei';border-bottom:1px solid #95B8E7; min-height:32px">
            	<label id="selectuser_tooltip_email_add_sj" class="easyui-linkbutton" style=" margin-left:-62px;float:left;" onclick="javascript:selectuser_fun('选择收件人','email_add_sj')">收件人：</label>
                <div style="padding: 0 0 6px;">
                	<input id="email_add_sj_select_id" type="hidden" value="<?php if($status == 3 )echo @$arr[0]->senderid.',';?>">
                    <textarea id="email_add_sj_select_user" name="" cols="" rows="" style="width:98%;font-family:'Microsoft Yahei'; border:0;overflow:auto;" readonly="readonly"><?php if($status == 3 )echo @$arr[0]->sender.',';?></textarea>
                	
				</div>  
            </div>
            <div id="addemailcc" style="padding-left: 64px;margin:5px;font-size: 12px; font-family:'Microsoft Yahei';border-bottom:1px solid #95B8E7;min-height:32px; display:none">
            	<label id="selectuser_tooltip_email_add_cc" class="easyui-linkbutton" data-options="plain:true" style=" margin-left:-62px;float:left;" onclick="javascript:selectuser_fun('选择抄送人','email_add_cc')">抄送人：</label>
                <div style="padding: 0 0 6px;">
                	<input id="email_add_cc_select_id" type="hidden">
                	<textarea id="email_add_cc_select_user" style="width:100%; font-family:'Microsoft Yahei'; border:0;overflow:auto;" readonly="readonly"></textarea>
				</div>  
            </div>
            <div style="padding-left: 68px;margin:5px;font-size: 12px; font-family:'Microsoft Yahei';border-bottom:1px solid #95B8E7; height:32px cursor:clear: both;">
            	<label style=" margin-top:4px;margin-left:-60px;float:left;color: #999;">主　题：</label>
                <div style="padding: 0 0 6px;">
                	<input id="emailtitle" class="panel-body" type="text" style="width:100%; height:22px;font-size: 14px;
font-weight: 700;border: 0;outline: 0;font-family:'Microsoft Yahei';" value="<?php if($status == 1 )echo @$arr[0]->title;else if($status == 2 ) echo 'Fw:'.@$arr[0]->title;else if($status == 3 ) echo 'Re:'.@$arr[0]->addressee.'，'.@$arr[0]->title;?>">
				</div>            	
            </div>  
            <div style="margin:5px;font-size: 12px; font-family:'Microsoft Yahei'; position:relative">
                <div style="float:left; position:absolute; margin-left:90px;">
                	<a class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-folder'" onclick="dialog_public('文件柜','file_cabinets/select_filebox_out/email')">个人文件柜</a>
                </div>
				<div style="float:left;"><input id="email_file_upload" name="email_file_upload" type="file" multiple></div>
                
                <script type="text/javascript">

				var fileList_email = new Array();
				var is_upload_all_email=false;
					<?php $timestamp = time();?>
					$(function() {
						$('#email_file_upload').uploadify({
							'height'          : 24,
							'width'           : 80,
							'buttonText'      : '上传附件',
							'removeCompleted' : false,
							'fileTypeDesc'    : '所有文件',
        					'fileTypeExts'    : '*.*',
							//'fileTypeExts'	  : '<?php echo $this->attachment_type_str;?>',
							'fileSizeLimit'   : '<?php echo $this->attachment_size;?>',
							'uploadLimit'	  : '50',
							'swf'             : '<?php echo base_url().'data/uploadify/uploadify.swf'?>',
							'uploader'        : '<?php echo base_url().'attachment/upload'?>',
							'formData' : {
								'attdir'    :'email',
								'timestamp' : '<?php echo $timestamp;?>',
								'token'     : '<?php echo md5('unique_salt' . $timestamp);?>'
							},
							'onSelect' : function(file){//当每个文件添加至队列后触发
								if(file.name.length > 213){
									this.queueData.errorMsg = '名称太长';
									$('#email_file_upload').uploadify('cancel', file.id);
									is_upload_all_email = false;	
								}else{
									is_upload_all_email = true;	
								}
												
							},
							'onUploadSuccess' : function(file, data, response) {
								//alert('The file ' + file.name + ' was successfully uploaded with a response of ' + response + ':' + data);
								//file.name = data+'.'+file.name;
								var obj = eval('(' + data + ')'); 
								if(obj.flag){									
									file.daterand = obj.str;
									file.name = obj.file_name;
									fileList_email.push(file);
									if($('#emailtitle').val() == ''){
										var str1 = obj.file_name;
										$('#emailtitle').val(str1.substr(0, str1.lastIndexOf('.')));
									}
								}else{
									alert(obj.str);
								}
							},
							'onQueueComplete' : function(queueData) {
								//alert(queueData.uploadsSuccessful + ' files were successfully uploaded.');
								//allPrpos(queueData.files);
								is_upload_all_email = false;
								//单击上传文件的取消按钮时，判断该文件是否已经上传过，如果已经上传过，需要做清理工作
								$("#email_file_upload-queue .cancel").on("click", function() {//JQUERY 2.0版本用on，1.9以前用live
									//取得本次取消的上传文件ID号		
									var fileId = $(this).parents(".uploadify-queue-item").attr("id");
									var fileInfo = null;
									//fileList中保存了所有的已上传文件信息。
									for (var i=0; i<fileList_email.length; i++) {
										if(fileList_email[i].id == fileId) {
											fileInfo = fileList_email[i];
											fileList_email.splice(i, 1);
											break;
										}
									}
									
									//如果文件已经上传（即fileInfo不为空）
									if (fileInfo != null) {
										//将已经上传的文件从上传文件队列中清除（不然取消该已上传的文件后，再选择相同的文件上传将会提示“文件已存在！”
										delete queueData.files[fileId];
										
										//将垃圾文件从后台服务器中清除
										//var suggest = {};
										//suggest.fileList = [fileInfo]; 
										
										$.post("<?php echo base_url().'attachment/upload_del'?>",{
											data:JSON.stringify(fileInfo),
											m:'email'
										},function(data,status){
											if(!data.status){
												$.messager.alert('提示','服务器端未能删除该文件','info');
												//alert('服务器端未能删除该文件');
											}
										},'JSON');
						
									}									
								});
							},
							'onCancel' : function(file) {
								$.messager.alert('提示','文件 ' + file.name + this.queueData.errorMsg + ' 被取消。','info');
							},
							'onSelectError': function (file, errorCode, errorMsg) {  
								
								switch (errorCode) {  
									case -100:  
										$.messager.alert('提示','上传的文件数量已经超出系统限制的' + $('#email_file_upload').uploadify('settings', 'queueSizeLimit') + '个文件！','info');
										//alert("上传的文件数量已经超出系统限制的" + $('#file_upload').uploadify('settings', 'queueSizeLimit') + "个文件！");  
										break;  
									case -110:  
										$.messager.alert('提示','文件 [' + file.name + '] 大小超出系统限制的' + $('#email_file_upload').uploadify('settings', 'fileSizeLimit') + ' 大小！','info');
										//alert("文件 [" + file.name + "] 大小超出系统限制的" + $('#file_upload').uploadify('settings', 'fileSizeLimit') + "大小！");  
										break;  
									case -120:  
										$.messager.alert('提示','文件 [' + file.name + '] 大小异常！','info');
										//alert("文件 [" + file.name + "] 大小异常！");  
										break;  
									case -130:  
										$.messager.alert('提示','文件 [' + file.name + '] 类型不正确！','info');
										//alert("文件 [" + file.name + "] 类型不正确！");  
										break;  
								}  
								return false;  
							},
							'onFallback': function () {  
								$.messager.confirm('警告', '您未安装FLASH控件，无法上传！是否立即安装?', function(r){
									if (r){
										window.open('https://get.adobe.com/cn/flashplayer/');
									}
								});
							}
						});
					});

				</script>
					
            </div>
        </div>
        <div style="padding:0 12px 12px; clear:both">
            <script type="text/plain" id="email_editor">
			<?php 
			if($status == 1 ){//重发
				echo @$arr[0]->content;
			}else if($status == 2){//转发
				echo "<br><br><br><br><br><span style='font-size:12px;'>------------------ 转发消息 ---------------------<br>";
				echo "发件人：".@$arr[0]->sender.'<br>';
				echo "日　期：".@$arr[0]->sendertime.'<br>';
				echo "收信人：".@$arr[0]->addressee2.'<br>';
				echo "标　题：".@$arr[0]->title.'<br><br></span>';
				echo @$arr[0]->content;
			}else if($status == 3){//回复
				echo "<br><br><br><br><br><span style='font-size:12px;'>------------------ 来信回复 ---------------------<br>";
				echo "在 ".@$arr[0]->sendertime.'&nbsp;';
				echo @$arr[0]->sender.' 写到：';
				echo @$arr[0]->content;
			}
			
			?>
            </script>  
            <script type="text/javascript">
                UE.getEditor('email_editor',{
                    //这里可以选择自己需要的工具按钮名称,此处仅选择如下五个
                    toolbars:[['source', '|', 'undo', 'redo', '|',
                    'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'removeformat', 'formatmatch', 'autotypeset', 'pasteplain', '|', 'forecolor', 'backcolor', '|',
                    'paragraph', 'fontfamily', 'fontsize', '|',
                    'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|',
                    'link', 'unlink', '|',
                    'emotion', 'scrawl', '|',
                    'horizontal', 'date', 'time', 'spechars', 'snapscreen', '|',
                    'inserttable']],
                    autoClearinitialContent:false,//focus时自动清空初始化时的内容
                    wordCount:false,//关闭字数统计
                    elementPathEnabled:false,//关闭elementPath
                    initialFrameHeight:200,//默认的编辑区域高度
					initialFrameWidth:"100%"
                });
            </script>
        </div>
        <div id="EmailNewMoreOptionsBox" style="display:none; padding:0 12px 12px;">
            <input id="email_add_important_check" type="checkbox" name="qx" value="1" /><label for="email_add_important_check">紧急</label>
            <input id="email_add_alert_check" type="checkbox" name="qx" value="1" checked="checked"/><label for="email_add_alert_check">内部短信提醒</label>
        </div>
        <div style="padding:0 12px 50px;">
            <div style="float:left;">
                <a href="#" class="easyui-linkbutton emailaddsub" data-options="iconCls:'icon-ok'" onclick="addemail()">发送</a>
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="javascript:emailclose();">取消</a>
            </div>
            <div style="float:right;">
                <a href="#" class="easyui-linkbutton" data-options="plain:true" >发件人：<?php echo $this->session->userdata('user_name');?></a>
                <a id="EmailNewMoreOptionsId" href="#" class="easyui-linkbutton" data-options="plain:true,iconAlign:'right',iconCls:'accordion-collapse'"><span id="EmailNewMoreOptionsText">更多选项</span></a>
            </div>
        </div>
    </div>
</div>

<style>
	#edui1{width:100% !important}/* 这个ID为编辑器的ID */
	#edui1_iframeholder{width:100% !important}/* 这个ID为编辑器可编辑区域的ID */
</style>

<script>
$(document).ready(function(){
	$("#EmailNewMoreOptionsId").click(function(){
		var v = $("#EmailNewMoreOptionsBox").css("display");
		if(v == 'none'){
			$("#EmailNewMoreOptionsBox").show();
			$('#EmailNewMoreOptionsId').linkbutton({iconCls:'accordion-expand'});
			$("#EmailNewMoreOptionsText").empty().append('隐藏选项');
		}else{
			$("#EmailNewMoreOptionsBox").hide();
			$('#EmailNewMoreOptionsId').linkbutton({iconCls:'accordion-collapse'});
			$("#EmailNewMoreOptionsText").empty().append('更多选项');
		}
	});
	
	selectuser_tooltip('选择收件人','email_add_sj');//tooltip提示
});



function addemail(){//进行相应检查后发送邮件
	if($("#email_add_sj_select_user").val() == ''){//如果收件人为空，则直接弹出选择收件人对话框，不提示
		selectuser_fun('选择收件人','email_add_sj');
		return false;
	}else if(is_upload_all_email === true){//如果有附件正在上传中，则取消提交并返回
		$.messager.alert('提示','附件正在上传中，请稍后提交！','warning');
		return false;
	}else if($("#emailtitle").val()==""){//如果主题为空，则提示是否需要填写主题，否则由系统自动设置
		$.messager.alert('提示','请填写邮件主题！','warning');
		$("#emailtitle").focus();
		return false;
		/*
		$.messager.confirm('提示', '你真的不需要写主题吗?', function(r){
			if (!r){
				$("#emailtitle").focus();
				return false;
			}
		});
		*/	
	}else{
		$('.emailaddsub').linkbutton('disable');//发送数据前禁用发送按钮防止重复提交
		
		var attdaterand='',attnames='',attsize='';
		for(var i=0; i<fileList_email.length; i++){
			attdaterand += fileList_email[i].daterand+',';
			attnames += fileList_email[i].name+'*';
			attsize += fileList_email[i].size+',';//所有附件的和
		}
		fileList_email.length = 0;
		$.post("<?php echo base_url()?>email/emailaddpost",{
			p_sj_id:$("#email_add_sj_select_id").val(),
			p_sj_user:$("#email_add_sj_select_user").val(),
			p_cc_id:$("#email_add_cc_select_id").val(),
			p_cc_user:$("#email_add_cc_select_user").val(),
			p_att_id:attdaterand,
			p_att_name:attnames,
			p_att_size:attsize,
			p_title:$("#emailtitle").val(),
			p_content:getContent('email_editor'),
			p_important:$("#email_add_important_check").is(':checked'),//是否重要
			p_sms:$("#email_add_alert_check").is(':checked'),//是否短信提醒
		},
		function(data,status){
			if(data.success){
				$('#email_in_list').datagrid('reload');//发送成功后刷新收件箱和发件箱
				$('#email_sent_list').datagrid('reload');
				$.messager.confirm('提示', '邮件发送成功，你要继续发送邮件吗?', function(r){
					if (r){
						
						$("#email_add_sj_select_id").val('');
						$("#email_add_sj_select_user").val('');
						$("#email_add_cc_select_id").val('');
						$("#email_add_cc_select_user").val('');
						$("#emailtitle").val('');
						UE.getEditor('email_editor').setContent('');
						$('.emailaddsub').linkbutton('enable');//发送数据前禁用发送按钮防止重复提交
						
						var attdaterand='',attnames='',attsize='',fileList_email=[],fileInfo = null;//清空附件相关变量
						$('#email_file_upload').uploadify('cancel', '*');//关闭附件列表
						$("#emailtitle").focus();
						return false;
					}else{
						$('#main-tab').tabs('close', '新邮件')
					}
				});	
			}else{
				$.messager.alert('错误','发送失败！','error');
			}
		},'json');
	}

}



function emailclose(){//如果邮件正在编辑，则弹出对话框询问
	if(getContent('email_editor') != ''){
		$.messager.confirm('提示', '邮件正在编辑，确定退出吗?', function(r){
			if (r){
				$('#main-tab').tabs('close', '新邮件');
			}
		});
	}else{
		$('#main-tab').tabs('close', '新邮件');
	}
}

function emailcc(){//抄送方法
	var v = $("#addemailcc").css("display");
	if(v == 'none'){
		$("#emailcc span:last").empty().append('删除抄送');
		$('#addemailcc').show();
		selectuser_tooltip('选择抄送人','email_add_cc');//tooltip提示		
	}else{
		var cc = $("#email_add_cc_select_id").val();
		if(cc != ''){
			$.messager.confirm('提示', '要删除所有抄送地址吗?', function(r){
				if (r){
					$("#emailcc span:last").empty().append('抄送');
					$('#addemailcc').hide();
					$("#email_add_cc_select_id").val('');
					$("#email_add_cc_select_user").val('')
				}
			});	
		}else{
			$("#emailcc span:last").empty().append('抄送');
			$('#addemailcc').hide();	
		}
		$('#selectuser_tooltip_email_add_cc').tooltip('destroy');//销毁选择用户提示
	}
}

function eattopen(date,filename,oriname){//打开附件
	oriname = encodeURIComponent(oriname);
	window.open("<?php echo base_url('email/attopen');?>/"+date+'/'+filename+'/'+oriname);
}

function setemail_att_obj(m,id,name,size){
	if(id.length > 0){
		//alert(name);
		//删除最后一个逗号
		id=id.substring(0,id.length-1);
		size=size.substring(0,size.length-1);
		name=name.substring(0,name.length-1);
		
		//把附件的ID和名称按分隔符分割为数组
		var ids= new Array(); //定义一数组 
			ids=id.split(","); //字符分割 
		var sizes= new Array(); //定义一数组 
			sizes=size.split(","); //字符分割 
		var names= new Array(); //定义一数组 
			names=name.split("*"); //字符分割 
		
		//循环赋值给fileList数组
		for (i=0;i<ids.length ;i++ ){ 
			//var att_arr=id[i].split("_"); //分割日期_文件随机码_分解大小字符，以备显示文件大小
			var att_files = {};
				att_files = {
					'id': m+'_att_'+i,
					'daterand': ids[i], //属性名用引号括起来，属性间由逗号隔开
					'name': names[i],
					'size': sizes[i]
				};			
			fileList_email.push(att_files);
			//var attsize = size;//所有附件的和
			
			$("#"+m+"_file_upload-queue").append("<div id='"+m+"_att_"+i+"' class='uploadify-queue-item'><div class='cancel'><a href=\"javascript:$('#"+m+"_file_upload').uploadify('cancel', '"+m+"_att_"+i+"')\">X</a></div><span class='fileName'>"+subStringCh(names[i], 36, true)+"("+renderSize(sizes[i])+")</span><span class='data'></span><div class='uploadify-progress'><div class='uploadify-progress-bar' style='width: 100%;'><!--Progress Bar--></div></div></div>");
		}
		
		$("#"+m+"_file_upload-queue .cancel").on("click", function() {//JQUERY 2.0版本用on，1.9以前用live
			//取得本次取消的上传文件ID号		
			var fileId = $(this).parents(".uploadify-queue-item").attr("id");
			//alert(fileId);
			//fileList中保存了所有的已上传文件信息。
			for (var i=0; i<fileList_email.length; i++) {
				if(fileList_email[i].id == fileId) {
					fileList_email.splice(i, 1);
					break;
				}
			}
		});
		//allPrpos ( fileList[0]);
	}
}
<?php 
if($status == 1 || $status == 2){
?>
setemail_att_obj('email','<?php echo  @$arr[0]->attachment_id;?>','<?php echo  @$arr[0]->attachment_name;?>','<?php echo  @$arr[0]->size;?>');
<?php 
}
?>
</script>
